var util = require('../../../libs/util.js');
var app = getApp();
var sliderWidth = 120; // 需要设置slider的宽度，用于计算中间位置
Page({
  data: {
    hasData: true,
    iotBox: []
  },
  onPullDownRefresh: function () {
    //wx.stopPullDownRefresh()
  },
  onLoad: function () {
    var that = this;
    wx.setNavigationBarTitle({ "title": app.appName +"--货品管理" });
    wx.showToast({
      title: "数据加载中，请稍候...",
      icon: 'loading',
      duration: 3000
    });
    this.loadData();
  },
  onShareAppMessage: function () {
    return {
      title: app.appName,
      path: '/pages/index/index'
    }
  },
  loadData: function () {
    var that = this;
    wx.request({
      url: app.server + '/wechat/wxapplet/getGoodsAll',
      method: 'GET',
      header: {
        'content-type': 'application/json',
        'Cookie':app.globalData.cookie
      },
      data: {
        openid: app.globalData.openid
      },
      success: function (res) {
        wx.hideToast();
        console.log(res.data)
        if (res.data.success) {
          that.setData({
            hasData: true,
            goodsData: res.data.data
          });
        } else {
          that.setData({
            hasData: false
          })
        };
      },
      fail: function (error) {
        wx.hideToast();
        console.log(error);
        that.setData({
          hasData: false
        })
      }
    })
  },
  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
      inputVal: "",
      inputShowed: false
    });
  },
  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function (e) {
    console.log(e.detail.value)
    this.setData({
      inputVal: e.detail.value
    });
  },
  newGoods: function () {
    wx.redirectTo({
      url: '/pages/warehouse/goods_new'
    })
  },
  warehouseMonitor: function () {
    wx.redirectTo({
      url: '/pages/warehouse/warehouse'
    })
  },
  warehouseStock: function () {
    wx.redirectTo({
      url: '/pages/warehouse/stock'
    })
  },
  goodsManage: function () {
    wx.redirectTo({
      url: '/pages/warehouse/goods'
    })
  }
})
